<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <!--本地资源提升加载速度-->
        <link rel="stylesheet" href="../plugins/element-ui-2.13.0/lib/theme-chalk/index.css">
        <!--<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">-->
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../plugins/echarts/echarts.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <!--本地资源提升加载速度-->
        <script src="../plugins/element-ui-2.13.0/lib/index.js"></script>
        <!--<script src="https://unpkg.com/element-ui/lib/index.js"></script>-->
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>会员数量</small></h1>
                <!--日期选择器控件-->
                <div class="block">
                    <h3><span class="demonstration">请选择需要查询的日期范围:</span></h3>
                    <el-date-picker
                            v-model="periodOfDate"
                            type="monthrange"
                            align="right"
                            unlink-panels
                            :default-value="defaultDate"
                            @change="changeDate"
                            range-separator="至"
                            start-placeholder="开始月份"
                            end-placeholder="结束月份"
                            format="yyyy-MM"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                </div>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>会员数量</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart1" style="height:570px"></div>
                </div>
            </div>
        </div>

        <script type="text/javascript">
            new Vue({
                el:'#app',
                data:{
                    //设置日历打开时默认显示的日期范围
                    defaultDate:[
                        new Date().setMonth(new Date().getMonth()-11),
                        new Date()
                    ],
                    //当前时间日期选择器特有的选项、属性
                    pickerOptions: {
                        //禁用未来的日期
                        disabledDate(periodOfDate){
                            if (periodOfDate>new Date()){
                                return true;
                            }
                            return false;
                        },
                        //快捷选项表
                        shortcuts: [{
                            text: '本月',
                            onClick(picker) {
                                picker.$emit('pick', [new Date(), new Date()]);
                            }
                        }, {
                            text: '今年至今',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date(new Date().getFullYear(), 0);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近六个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setMonth(start.getMonth() - 6);
                                picker.$emit('pick', [start, end]);
                            }
                        }]
                    },
                    //初始化显示的日期: 最近一年
                    periodOfDate: [
                        new Date().setMonth(new Date().getMonth()-11),
                        new Date()
                    ]
                },
                methods:{
                    //日期发生改变绑定的事件
                    changeDate(){
                        console.log("periodOfDate=="+this.periodOfDate);
                        axios.post("http://localhost:82/report/getMemberReportByDate.do",this.periodOfDate).then((res)=>{
                            myChart1.setOption(
                                {
                                    title: {
                                        text: '会员数量'
                                    },
                                    tooltip: {},
                                    legend: {
                                        data:['会员数量']
                                    },
                                    xAxis: {
                                        data: res.data.data.months
                                    },
                                    yAxis: {
                                        type:'value'
                                    },
                                    series: [{
                                        name: '会员数量',
                                        type: 'line',
                                        data: res.data.data.memberCount
                                    }]
                                });
                        });
                    }

                }
            });
        </script>

    </body>

    <script type="text/javascript">

        // 基于准备好的dom，初始化echarts实例
        var myChart1=echarts.init(document.getElementById('chart1'));

        // 使用刚指定的配置项和数据显示图表。
        //myChart.setOption(option);
        /**
         * 前端需要的数据模型
         *
         * {
         *      flag: true ,
         *      message: '会员数量统计成功！',
         *      data: {
         *           months: ['2020-01','2020-02'],
         *           memberCount:[10, 20]
         *      }
         * }
         *
         */
        axios.post("http://localhost:82/report/getMemberReport.do").then((res)=>{
            myChart1.setOption(
                {
                    title: {
                        text: '会员数量'
                    },
                    tooltip: {},
                    legend: {
                        data:['会员数量']
                    },
                    xAxis: {
                        data: res.data.data.months
                    },
                    yAxis: {
                        type:'value'
                    },
                    series: [{
                        name: '会员数量',
                        type: 'line',
                        data: res.data.data.memberCount
                    }]
                });
        });
    </script>

</html>
